using System;
using System.Collections.Generic;
using System.Management.Automation.Host;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;

namespace Fines.Powershell.PowershellMSBuildTask
{
    /// <summary>
    /// Implementation of PSHostUserInterface.
    /// Input methods are not implemented.
    /// </summary>
    public class PowershellHostUI : PSHostUserInterface
    {
        public PowershellHostUI( IPowershellTask task )
        {
            this.task = task;
            this.log = new TaskLoggingHelper( this.task );
            this.rawUI = new PowershellHostRawUI();
        }
        public override Dictionary<string, System.Management.Automation.PSObject> Prompt( string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions )
        {
            throw new NotImplementedException();
        }

        public override int PromptForChoice( string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice )
        {
            throw new NotImplementedException();
        }

        public override System.Management.Automation.PSCredential PromptForCredential( string caption, string message, string userName, string targetName, System.Management.Automation.PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options )
        {
            throw new NotImplementedException();
        }

        public override System.Management.Automation.PSCredential PromptForCredential( string caption, string message, string userName, string targetName )
        {
            throw new NotImplementedException();
        }

        public override PSHostRawUserInterface RawUI
        {
            get { return this.rawUI; }
        }

        public override string ReadLine()
        {
            throw new NotImplementedException();
        }

        public override System.Security.SecureString ReadLineAsSecureString()
        {
            throw new NotImplementedException();
        }

        public override void Write( ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value )
        {
            this.log.LogMessage( MessageImportance.High, value );
        }

        public override void Write( string value )
        {
            this.log.LogMessage( MessageImportance.High, value );
        }

        public override void WriteDebugLine( string message )
        {
            this.log.LogCommandLine( MessageImportance.Low, message );
        }

        public override void WriteErrorLine( string value )
        {
            this.log.LogError( value );
        }

        public override void WriteLine( string value )
        {
            this.log.LogMessage( MessageImportance.High, value );
        }

        public override void WriteProgress( long sourceId, System.Management.Automation.ProgressRecord record )
        {
            // nothing
        }

        public override void WriteVerboseLine( string message )
        {
            this.log.LogMessage( MessageImportance.Low, message );
        }

        public override void WriteWarningLine( string message )
        {
            this.log.LogWarning( message );
        }

        private readonly TaskLoggingHelper log;
        private readonly IPowershellTask task;
        private readonly PowershellHostRawUI rawUI;
    }
}
